package newBee.class3;

import common.ArrayUtils;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/corporate-flight-bookings/
 * 航班预定统计
 */
public class Code02_corpFlightBookings {
    public static void main(String[] args) {
        int[][] bookings = {{1, 2, 10}, {2, 3, 20}, {2, 5, 25}};
        int n = 5;
        int[] ans = corpFlightBookings(bookings, n);
        ArrayUtils.printArr(ans);
    }

    public static int[] corpFlightBookings(int[][] bookings, int n) {
        int[] ans = new int[n + 1];
        for (int[] book : bookings) {
            ans[book[0] - 1] += book[2];
            ans[book[1] + 1 - 1] -= book[2];
        }
        for (int i = 1; i < n; i++) {
            ans[i] += ans[i - 1];
        }
        return Arrays.copyOf(ans, n);
    }
}
